import mdp
import numpy as np


class Doc:
    
    train = u''' '''
    execute = u''' '''

def train(parameters):
    
    '''Returns classiffer'''
    
    file = parameters['file']

    data = np.genfromtxt(file, delimiter=parameters['delimiter'], usecols=(parameters['data_columns']))
    file.close()
    file.open()
    classes = np.genfromtxt(file, delimiter=parameters['delimiter'], dtype=np.str, usecols=(parameters['classes_column']))
    classiffer = mdp.nodes.GaussianClassifier()
    classiffer.train(data, classes)

    return classiffer
    
   
def execute(classiffer, test_data):
    
    '''Returns labels '''
    
    test_array = np.array(test_data)    
    return {'image_path':'', 'description':classiffer.label(test_array)}



if __name__ == '__main__':
    
    parameters = {}
    
    parameters['file'] = '/home/sylwek/Aptana Studio Workspace/pracamgr2/pracamgr2/site_media/datasets/learning/iris.data_1.txt'
    parameters['classes_column'] = (4)
    parameters['data_columns'] = (0,1,2,3)
    parameters['delimiter'] = ','
    
    classiffer = train(parameters)
    print classiffer
    
    